package com.多线程.ThreadPool;

import java.util.concurrent.Callable;

/**
 * 1.定义一个MyCallable任务类，实现Callable接口，且应该声明线程结束后返回结果的类型
 */

public class MyCallable implements Callable<String> {
    private int number;

    public MyCallable(int number) {
        this.number = number;
    }

    /**
     * 2.重写call方法，结果返回值类型与实现Callable接口声明的类型相同
     */

    @Override
    public String call() throws Exception {
        int sum=0;
        for (int i = 1; i <=number; i++) {
            sum+=i;
        }
        return Thread.currentThread().getName()+"计算1-"+number+"的和，结果是："+sum;
    }
}
